from Data_Process import *
from py2neo import Graph


# 需求2：根据当前商品推荐
def goods_related(goods_name):
    # self.g = Graph(
    #     host="127.0.0.1",
    #     http_port=7474,
    #     user="neo4j",
    #     password="gu13569740552")
    g = Graph('http://localhost:7474', user='neo4j', password='gu13569740552')
    # 限制最大输出结果项数为50
    limit_num = 50
    dp = DataProcess()
    # 当前浏览的商品名称抽象
    goods_cur = dp.get_goods_name(goods_name)
    print("当前商品名称抽象后为:{}".format(goods_cur))
    sql = "match (m:goods)-[:apply_to]-(:scene)-[:apply_to]-(n:goods) where '{0}' in n.name or '{0}' in n.synonym return m.name limit {1}".format(
        goods_cur, limit_num)
    answers = []
    ans = g.run(sql).data()
    for res in ans:
        answers.append(res['m.name'])
    return answers


if __name__ == '__main__':
    print("测试：小猪佩奇社会人佩琪T恤恶搞联名抖音潮牌男女半袖")
    res = goods_related("小猪佩奇社会人佩琪T恤恶搞联名抖音潮牌男女半袖")
    print(res)
